import argparse


class ArgumentParser:
    def __init__(self):
        self.parser = argparse.ArgumentParser(
            description='A translation tool that supports translations in any language pair.')

        # 参数配置优化：提供默认值和帮助信息
        self.parser.add_argument('--config_file', type=str, default='conf_v2.yaml',
                                 help='Path to the configuration file. Default is v2_conf.yaml')
        self.parser.add_argument('--model_name', type=str,
                                 help='Name of the translation model to be used')
        self.parser.add_argument('--input_file', type=str,
                                 help='Path to the input file for translation. ')
        self.parser.add_argument('--output_file_format', type=str,
                                 help='Format of the output file')
        self.parser.add_argument('--source_language', type=str,
                                 help='Source language code (e.g., en for English).')
        self.parser.add_argument('--target_language', type=str,
                                 help='Target language code (e.g., fr for French).')

    def parse_args(self):
        # 参数解析优化：异常处理
        try:
            arg = self.parser.parse_args()
            return arg
        except argparse.ArgumentError as e:
            # 当解析出错时，打印更详细的错误信息，然后退出
            print("Error parsing arguments: {}".format(e))
            self.parser.print_help()
            exit(1)


# 示例：创建ArgumentParser实例并解析参数
if __name__ == "__main__":
    parser = ArgumentParser()
    args = parser.parse_args()
    print(args)
